package User

import (
	"net/http"

	M "ICan/MySql"
	"ICan/errmsg"
	_ "github.com/go-sql-driver/mysql"
	"github.com/gin-gonic/gin"
)

type information struct {
	Infor_id int `json:"information_id"`
	Infor_context string `json:"information_context"`
	Infor_time string `json:"information_time"`
}

func FInformation(ctx *gin.Context){
	user_id := ctx.PostForm("user_id")
	sqlstr := `select information_id, information_context, information_time from information where information_user_id = ?`
	rows, _ := M.Db.Query(sqlstr, user_id)
	defer rows.Close()
	var infor = make([]information, 0)
	for rows.Next() {
		var u information
		rows.Scan(&u.Infor_id, &u.Infor_context, &u.Infor_time)
		infor = append(infor, information{
			Infor_id:u.Infor_id,
			Infor_context:u.Infor_context,
			Infor_time:u.Infor_time,
		})
	}
	code := errmsg.Succse
	data := map[string]interface{}{
		"code":code,
		"msg":errmsg.GetErrMSg(code),
		"data":infor,
	}
	ctx.JSON(http.StatusOK, data)
}